package org.ainlolcat.ainscience.templates;

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author ainlolcat
 * Date: 10/25/11
 */
public class TemplateFactory {
    public static Template parse(InputStream is, String filename) throws JDOMException, IOException {
        Document doc = new SAXBuilder().build(is);
        if (!doc.getRootElement().getName().equals("template"))
            throw new JDOMException("wrong root");
        return new Template(doc, filename);
    }

    public static Template parse(String filename) throws IOException, JDOMException {
        FileInputStream fis = null;
        fis = new FileInputStream(filename);
        Template temp = parse(fis, filename);
        fis.close();
        return temp;
    }
}

